<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/mb/jsp/common.jsp" %>

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>宝箱</title>
</head>
<body ontouchstart="">
<div class="detailTop pf w100 of">
    <div class="w100 of tc cf f18">
        <span class="pa" style="left: 2px;" onclick="javascript:history.back();"><img src="mb/images/top_back_white.png" style="margin-top: 4px;height: 40px;width: 40px;"/></span>
		      宝箱
    </div>
</div>

<div class="container db jz mgt45">

    <div id="container">
    	<section class="mgt10 bcf w95 jz of">
    		<div class="w95 jz mgt10 mgb10 df">
    			<img src="mb/images/treasure.png" class="db" style="height:72px;flex-shrink: 0;">
    			<div class="mgl10" style="flex-grow: 2;">
    				<h4 class="c3 f16">'+obj.redbagname+'</h4>
    				<p class="c9 f13 mgt10">2017-07-10 16:52:11</p>
    				<div class="flexBox mgt10">
    					<p class="orange f15">'+obj.state+'</p>
    					<button class="f14 tc db cf btnOrange lh2" style="width:30%;">打开</button>
    				</div>
    			</div>
    		</div>
    	</section>

        <div id="resText"></div><!--resText-->
        <div id="loading" class="w100">
            <img src="mb/images/loading.gif" alt="正在加载" class="db jz hauto" style="width: 15px;">
            <div class="w100 tc f10 c9">正在加载</div>
        </div>
        
        
	</div>

<script>

    //加载新数据
    function getData() {
        $.ajax({
            url: "PlugServlet",
            data: JSON.stringify({m: 1680}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {
                showProgressDg();
            },
            success: function (data) {
            	console.log(data.list);
               if (data.state == 1) {
                  showData(data.list);
                } else {
                    // 其他错误弹出提示
                    showToast(data.info);
                }
            },
            error: function (data) {
                showToast(data.info);
            },
            complete: function () {
                closeProgressDg();
            }
        });
    }
    
    
     function showData(list)
    {
    	var htmlStr="";
    	$.each(list, function(index, obj) 
    	{
    		/* var tmpimg=obj.prestigeimage.split(";")[0]; */
    		var projectid = obj.prestigeid;
			var btnBlock = "";
    		if(obj.prestigeintro == ""||obj.prestigeintro == undefined||obj.prestigeintro == null){
    		   obj.prestigeintro = "暂无";
    		};
			if(obj.isget == 0){
				btnBlock='<button class="w100 tc cf f15 modifyBtn" onclick="getSth('+ projectid +')">领取</button>';
			}
			else if(obj.isget == 1){
			    btnBlock = '<button class="w100 tc c6 f15 modifyBtn" style="background:#ddd;">已领取</button>'; 
			}
			
			
			var num = obj.limitenum - obj.buynum;
    		
    		if(num == 0){
    		   num = "0(无库存)";
    		   btnBlock = btnBlock = '<button class="w100 tc c6 f15 modifyBtn" style="background:#ddd;">不可领取</button>';
    		}
    		else if(num < 0){
    		  num = "error";
    		  btnBlock = btnBlock = '<button class="w100 tc c6 f15 modifyBtn" style="background:#ddd;">不可领取</button>';
    		}
    		
    		
    		
    		//新增的iscanback属性
    		var iscanback = obj.iscanback;
    		var canbackLable = "";
    		if(iscanback == 0){
    		   canbackLable = '<p class="c9 f12 lh18">(不支持回购)&nbsp;&nbsp;剩余:'+num+'</p>';
    		}
    		else if(iscanback == 1){
    		  canbackLable = '<p class="c9 f12 lh18">回购价：'+obj.callbackprice+'&nbsp;&nbsp;剩余:'+num+'</p>';
    		}
    		
			
    		htmlStr +=
	    		   	'<section class="proSection pr w100 bcf">'+
					   '<a href="mb/jsp/shengWangShangChengDetail.jsp?prestigeid=' + projectid + '" class="w100 db">'+
				            '<article class="of clearfix jz">'+
				                '<div class="fl" style="margin-left:2%;">'+
				                  '<img src="'+getBaseImgUrl(tmpimg)+'" class="kmImg mgt15">'+
				                '</div>'+
				                '<div class="fr dib" style="margin-right:2%;margin-right:2%;margin-left:2%;width:68%;">'+
				                    '<h5 class="c3 f13 mgt10 lh2">'+obj.prestigename+'</h5>'+
				                    '<p class="c9 f12 lh2">活跃值：'+obj.requirevalue+'&nbsp;&nbsp;市场价:<span class="lineThroughSpan">'+obj.oldprice+'</span></p>'+
				                    canbackLable+
				                    '<p class="c9 f12 lh18" style="margin-top: 3px;">简介：'+obj.prestigeintro+'</p>'+
				                '</div>'+
				            '</article>'+
				        '</a>'+
				        '<div style="width:96%;border-top:1px solid #ececec;padding:7px 0;" class="jz mgt10">'+
				           btnBlock +
				        '</div>'+
					'</section>'; 
    		
    	});
    	
    	 $("#resText").after(htmlStr);
    }
    
    
   // 领取
	function getSth(prestigeid) {
        $.ajax({
            url: "PlugServlet",
            data: JSON.stringify({m: 1662,prestigeid:prestigeid}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {

            },
            success: function (data) {
 				console.log(data);
               if (data.state == 1) {
                  // 成功弹出提示
                  showToast(data.info);
                  setTimeout('window.location.reload()', 1600);
                } else {
                    // 其他错误弹出提示
                   showToast(data.info);
                }
            },
            error: function (data) {
                showToast(data.info);
            },
            complete: function () {
                closeProgressDg();
            }
        });
    } 
    
    
    
    $(document).ready(function(){
	
		getData();
	  
	});
</script>
</body>
</html>
